home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_12 / owen / emmfix.c < prev   
Encoding:
C/C++ Source or Header  |  1995-10-04  |  871 b   |  43 lines

  1. #define BIG unsigned long
  2. #define WORD unsigned int
  3.  
  4. void fixems(int is16, BIG *page,
  5. BIG *offset, WORD *count) {
  6.   BIG physical;
  7.  
  8.   if (is16) {
  9.     /* reconstitute linear address from
  10.     16-bit DMA page and offset form;
  11.     reconstitute count (in 16-bit DMA it's
  12.     the count of 16-bit words); adjust the
  13.     resulting address to anticipate
  14.     HIMEM/EMM386 bug. */
  15.  
  16.     physical =
  17.     (((*page & 0xFE)<<16) |
  18.     (*offset << 1))
  19.     -
  20.     ( (((BIG)*count)+1) << 1 );
  21.  
  22.     /* deconstruct the adjusted linear
  23.     address to the page and offset
  24.     form. */
  25.  
  26.     *page =   (physical & 0xFE0000) >> 16;
  27.     *offset = (physical & 0x1FFFE) >> 1;
  28.  
  29.     return;
  30.     }
  31.  
  32.  
  33.   /* same as above, but considerably
  34.      simpler in 8-bit DMA. */
  35.  
  36.   physical = ((*page << 16) | (*offset))
  37.   - (((BIG)*count)+1);
  38.  
  39.   *page = (physical & 0xFF0000) >> 16;
  40.   *offset = physical & 0xFFFF;
  41. }
  42.  
  43.